<?php
namespace Frame\Libs;

use Frame\Vendor\Smarty;

abstract class BaseController{
    protected $smarty=NULL;
    public function __construct() {
        $this->initSmarty();
    }
    private function initSmarty(){
        $smarty=new Smarty();
        $smarty->left_dilimiter="{";
        $smarty->right_dilimiter="}";
        $smarty->setTemplateDir(VIEW_PATH);//设置视图文件目录
        // 修复编译目录路径，从系统临时目录改为项目内的templates_c目录，便于管理缓存
        $smarty->setCompileDir(ROOT_PATH . DS . 'templates_c' . DS);//设置编译目录
        $this->smarty=$smarty;
        $smarty->caching = false;//关闭输出缓存
    }
    
    // 实现URL重定向方法
    protected function redirect($url) {
        header("Location: " . $url);
        exit();
    }
    
    // 检查用户登录状态
    protected function checkLogin() {
        session_start();
        if (!isset($_SESSION['admin_user'])) {
            $this->redirect('admin.php?c=Login&a=login');
        }
    }
}